package com.myshop.service.impl;

import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myshop.dao.UserDao;
import com.myshop.entity.User;
import com.myshop.service.UserService;
import org.springframework.stereotype.Service;

/**
 * 用户模块的用户实体(User)表服务实现类
 *
 * @author makejava
 * @since 2023-07-21 16:17:55
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Override
    public User queryByName(String name) {
        try {
            return this.query()
                    .eq("name", name)
                    .one();
        } catch (MybatisPlusException e) {
            System.out.println("该用户名不存在");
            return null;
        }
    }

    @Override
    public boolean addAdminUser(String name, String password, String sex) {
        return this.save(new User()
                .setName(name)
                .setPassword(password)
                .setRole(1)
                .setSex(sex)
        );
    }
}

